In [1]:
import pandas as pd
import numpy as np
import shutil
import multiprocessing
from datetime import datetime

import tensorflow as tf
from tensorflow.python.feature_column import feature_column
from tensorflow.contrib.learn import learn_runner
from tensorflow import data

print(tf.__version__)


/Users/khalidsalama/anaconda/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)
1.4.0

TF Custom Estimator to Build a NN Autoencoder for Feature Extraction


In [2]:
MODEL_NAME = 'auto-encoder-01'

TRAIN_DATA_FILES_PATTERN = 'data/data-*.csv'

RESUME_TRAINING = False

MULTI_THREADING = True

1. Define Dataset Metadata


In [3]:
FEATURE_COUNT = 64

HEADER = ['key']
HEADER_DEFAULTS = [[0]]
UNUSED_FEATURE_NAMES = ['key']
CLASS_FEATURE_NAME = 'CLASS'
FEATURE_NAMES = []  

for i in range(FEATURE_COUNT):
    HEADER += ['x_{}'.format(str(i+1))]
    FEATURE_NAMES += ['x_{}'.format(str(i+1))]
    HEADER_DEFAULTS += [[0.0]]

HEADER += [CLASS_FEATURE_NAME]
HEADER_DEFAULTS += [['NA']]

print("Header: {}".format(HEADER))
print("Features: {}".format(FEATURE_NAMES))
print("Class Feature: {}".format(CLASS_FEATURE_NAME))
print("Unused Features: {}".format(UNUSED_FEATURE_NAMES))


Header: ['key', 'x_1', 'x_2', 'x_3', 'x_4', 'x_5', 'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14', 'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22', 'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30', 'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38', 'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46', 'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54', 'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62', 'x_63', 'x_64', 'CLASS']
Features: ['x_1', 'x_2', 'x_3', 'x_4', 'x_5', 'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14', 'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22', 'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30', 'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38', 'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46', 'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54', 'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62', 'x_63', 'x_64']
Class Feature: CLASS
Unused Features: ['key']

2. Define CSV Data Input Function


In [4]:
def parse_csv_row(csv_row):
    
    columns = tf.decode_csv(csv_row, record_defaults=HEADER_DEFAULTS)
    features = dict(zip(HEADER, columns))
    
    for column in UNUSED_FEATURE_NAMES:
        features.pop(column)

    target = features.pop(CLASS_FEATURE_NAME)

    return features, target

In [5]:
def csv_input_fn(files_name_pattern, mode=tf.estimator.ModeKeys.EVAL, 
                 skip_header_lines=0, 
                 num_epochs=None, 
                 batch_size=200):
    
    shuffle = True if mode == tf.estimator.ModeKeys.TRAIN else False
    
    print("")
    print("* data input_fn:")
    print("================")
    print("Input file(s): {}".format(files_name_pattern))
    print("Batch size: {}".format(batch_size))
    print("Epoch Count: {}".format(num_epochs))
    print("Mode: {}".format(mode))
    print("Shuffle: {}".format(shuffle))
    print("================")
    print("")
    
    file_names = tf.matching_files(files_name_pattern)

    dataset = data.TextLineDataset(filenames=file_names)
    dataset = dataset.skip(skip_header_lines)
    
    if shuffle:
        dataset = dataset.shuffle(buffer_size=2 * batch_size + 1)
        
    num_threads = multiprocessing.cpu_count() if MULTI_THREADING else 1
    
    dataset = dataset.batch(batch_size)
    dataset = dataset.map(lambda csv_row: parse_csv_row(csv_row), num_parallel_calls=num_threads)
    
    dataset = dataset.repeat(num_epochs)
    iterator = dataset.make_one_shot_iterator()
    
    features, target = iterator.get_next()

    return features, target

In [6]:
features, target = csv_input_fn(files_name_pattern="")
print("Feature read from CSV: {}".format(list(features.keys())))
print("Target read from CSV: {}".format(target))


* data input_fn:
================
Input file(s): 
Batch size: 200
Epoch Count: None
Mode: eval
Shuffle: False
================

Feature read from CSV: ['x_1', 'x_2', 'x_3', 'x_4', 'x_5', 'x_6', 'x_7', 'x_8', 'x_9', 'x_10', 'x_11', 'x_12', 'x_13', 'x_14', 'x_15', 'x_16', 'x_17', 'x_18', 'x_19', 'x_20', 'x_21', 'x_22', 'x_23', 'x_24', 'x_25', 'x_26', 'x_27', 'x_28', 'x_29', 'x_30', 'x_31', 'x_32', 'x_33', 'x_34', 'x_35', 'x_36', 'x_37', 'x_38', 'x_39', 'x_40', 'x_41', 'x_42', 'x_43', 'x_44', 'x_45', 'x_46', 'x_47', 'x_48', 'x_49', 'x_50', 'x_51', 'x_52', 'x_53', 'x_54', 'x_55', 'x_56', 'x_57', 'x_58', 'x_59', 'x_60', 'x_61', 'x_62', 'x_63', 'x_64']
Target read from CSV: Tensor("IteratorGetNext:64", shape=(?,), dtype=string)

3. Define Feature Columns


In [7]:
def get_feature_columns():

    feature_columns = {feature_name: tf.feature_column.numeric_column(feature_name)
                       for feature_name in FEATURE_NAMES}

    return feature_columns

4. Define Autoencoder Model Function


In [8]:
def autoencoder_model_fn(features, labels, mode, params):
    
    feature_columns = list(get_feature_columns().values())
    
    input_layer_size = len(feature_columns)
    
    encoder_hidden_units = params.encoder_hidden_units
    
    # decoder units are the reverse of the encoder units, without the middle layer (redundant)
    decoder_hidden_units = encoder_hidden_units.copy()  
    decoder_hidden_units.reverse()
    decoder_hidden_units.pop(0)
    
    output_layer_size = len(FEATURE_NAMES)
    
    he_initialiser = tf.contrib.layers.variance_scaling_initializer()
    l2_regulariser = tf.contrib.layers.l2_regularizer(scale=params.l2_reg)
    
  
    print("[{}]->{}-{}->[{}]".format(len(feature_columns)
                                     ,encoder_hidden_units
                                     ,decoder_hidden_units,
                                     output_layer_size))

    is_training = (mode == tf.estimator.ModeKeys.TRAIN)
    
    # input layer
    input_layer = tf.feature_column.input_layer(features=features, 
                                                feature_columns=feature_columns)
    
    # Adding Gaussian Noise to input layer
    noisy_input_layer = input_layer + (params.noise_level * tf.random_normal(tf.shape(input_layer)))
    
    # Dropout layer
    dropout_layer = tf.layers.dropout(inputs=noisy_input_layer, 
                                     rate=params.dropout_rate, 
                                     training=is_training)

#     # Dropout layer without Gaussian Nosing
#     dropout_layer = tf.layers.dropout(inputs=input_layer, 
#                                       rate=params.dropout_rate, 
#                                       training=is_training)

    # Encoder layers stack
    encoding_hidden_layers = tf.contrib.layers.stack(inputs= dropout_layer,
                                                     layer= tf.contrib.layers.fully_connected,
                                                     stack_args=encoder_hidden_units,
                                                     #weights_initializer = he_init,
                                                     weights_regularizer =l2_regulariser,
                                                     activation_fn = tf.nn.relu
                                                    )
    # Decoder layers stack
    decoding_hidden_layers = tf.contrib.layers.stack(inputs=encoding_hidden_layers,
                                                     layer=tf.contrib.layers.fully_connected,                
                                                     stack_args=decoder_hidden_units,
                                                     #weights_initializer = he_init,
                                                     weights_regularizer =l2_regulariser,
                                                     activation_fn = tf.nn.relu
                                                    )
    # Output (reconstructed) layer
    output_layer = tf.layers.dense(inputs=decoding_hidden_layers, 
                             units=output_layer_size, activation=None)
    
    # Encoding output (i.e., extracted features) reshaped
    encoding_output = tf.squeeze(encoding_hidden_layers)
    
    # Reconstruction output reshaped (for loss calculation)
    reconstruction_output =  tf.squeeze(output_layer)
    
    # Provide an estimator spec for `ModeKeys.PREDICT`.
    if mode == tf.estimator.ModeKeys.PREDICT:
        
        # Convert predicted_indices back into strings
        predictions = {
            'encoding': encoding_output,
            'reconstruction': reconstruction_output
        }
        export_outputs = {
            'predict': tf.estimator.export.PredictOutput(predictions)
        }
        
        # Provide an estimator spec for `ModeKeys.PREDICT` modes.
        return tf.estimator.EstimatorSpec(mode,
                                          predictions=predictions,
                                          export_outputs=export_outputs)
    
    # Define loss based on reconstruction and regularization
    loss = tf.losses.mean_squared_error(tf.squeeze(input_layer), reconstruction_output) 
    loss = loss + tf.losses.get_regularization_loss()
                         
    # Create Optimiser
    optimizer = tf.train.AdamOptimizer(params.learning_rate)

    # Create training operation
    train_op = optimizer.minimize(
        loss=loss, global_step=tf.train.get_global_step())

    # Calculate root mean squared error as additional eval metric
    eval_metric_ops = {
        "rmse": tf.metrics.root_mean_squared_error(
            tf.squeeze(input_layer), reconstruction_output)
    }
                                                     
    # Provide an estimator spec for `ModeKeys.EVAL` and `ModeKeys.TRAIN` modes.
    estimator_spec = tf.estimator.EstimatorSpec(mode=mode,
                                                loss=loss,
                                                train_op=train_op,
                                                eval_metric_ops=eval_metric_ops)
    return estimator_spec


def create_estimator(run_config, hparams):
    estimator = tf.estimator.Estimator(model_fn=autoencoder_model_fn, 
                                  params=hparams, 
                                  config=run_config)
    
    print("")
    print("Estimator Type: {}".format(type(estimator)))
    print("")

    return estimator

5. Run Experiment

a. Create Experiment Function


In [9]:
def generate_experiment_fn(**experiment_args):

    def _experiment_fn(run_config, hparams):

        train_input_fn = lambda: csv_input_fn(
            TRAIN_DATA_FILES_PATTERN,
            mode = tf.contrib.learn.ModeKeys.TRAIN,
            num_epochs=hparams.num_epochs,
            batch_size=hparams.batch_size
        )

        eval_input_fn = lambda: csv_input_fn(
            TRAIN_DATA_FILES_PATTERN,
            mode=tf.contrib.learn.ModeKeys.EVAL,
            num_epochs=1,
            batch_size=hparams.batch_size
        )

        estimator = create_estimator(run_config, hparams)

        return tf.contrib.learn.Experiment(
            estimator,
            train_input_fn=train_input_fn,
            eval_input_fn=eval_input_fn,
            eval_steps=None,
            **experiment_args
        )

    return _experiment_fn

b. Set the parameters


In [10]:
TRAIN_SIZE = 2000
NUM_EPOCHS = 1000
BATCH_SIZE = 100
NUM_EVAL = 10
CHECKPOINT_STEPS = int((TRAIN_SIZE/BATCH_SIZE) * (NUM_EPOCHS/NUM_EVAL))

hparams  = tf.contrib.training.HParams(
    num_epochs = NUM_EPOCHS,
    batch_size = BATCH_SIZE,
    encoder_hidden_units=[30,3],
    learning_rate = 0.01,
    l2_reg = 0.0001,
    noise_level = 0.0,
    dropout_rate = 0.1)

model_dir = 'trained_models/{}'.format(MODEL_NAME)

run_config = tf.contrib.learn.RunConfig(
    save_checkpoints_steps=CHECKPOINT_STEPS,
    tf_random_seed=19830610,
    model_dir=model_dir
)

print(hparams)
print("Model Directory:", run_config.model_dir)
print("")
print("Dataset Size:", TRAIN_SIZE)
print("Batch Size:", BATCH_SIZE)
print("Steps per Epoch:",TRAIN_SIZE/BATCH_SIZE)
print("Total Steps:", (TRAIN_SIZE/BATCH_SIZE)*NUM_EPOCHS)
print("Required Evaluation Steps:", NUM_EVAL) 
print("That is 1 evaluation step after each",NUM_EPOCHS/NUM_EVAL," epochs")
print("Save Checkpoint After",CHECKPOINT_STEPS,"steps")


[('batch_size', 100), ('dropout_rate', 0.1), ('encoder_hidden_units', [30, 3]), ('l2_reg', 0.0001), ('learning_rate', 0.01), ('noise_level', 0.0), ('num_epochs', 1000)]
Model Directory: trained_models/auto-encoder-01

Dataset Size: 2000
Batch Size: 100
Steps per Epoch: 20.0
Total Steps: 20000.0
Required Evaluation Steps: 10
That is 1 evaluation step after each 100.0  epochs
Save Checkpoint After 2000 steps

c. Run the experiment using learn_runner


In [11]:
if not RESUME_TRAINING:
    print("Removing previous artifacts...")
    shutil.rmtree(model_dir, ignore_errors=True)
else:
    print("Resuming training...") 


tf.logging.set_verbosity(tf.logging.INFO)

time_start = datetime.utcnow() 
print("Experiment started at {}".format(time_start.strftime("%H:%M:%S")))
print(".......................................") 

learn_runner.run(
    experiment_fn=generate_experiment_fn(
    ),
    run_config=run_config,
    schedule="train_and_evaluate", #'train_and_evaluate'
    hparams=hparams
)

time_end = datetime.utcnow() 
print(".......................................")
print("Experiment finished at {}".format(time_end.strftime("%H:%M:%S")))
print("")
time_elapsed = time_end - time_start
print("Experiment elapsed time: {} seconds".format(time_elapsed.total_seconds()))


Removing previous artifacts...
Experiment started at 19:20:43
.......................................
WARNING:tensorflow:RunConfig.uid (from tensorflow.contrib.learn.python.learn.estimators.run_config) is experimental and may change or be removed at any time, and without warning.
INFO:tensorflow:Using config: {'_task_type': None, '_task_id': 0, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x121ab5a20>, '_master': '', '_num_ps_replicas': 0, '_num_worker_replicas': 0, '_environment': 'local', '_is_chief': True, '_evaluation_master': '', '_tf_config': gpu_options {
  per_process_gpu_memory_fraction: 1
}
, '_tf_random_seed': 19830610, '_save_summary_steps': 100, '_save_checkpoints_secs': None, '_log_step_count_steps': 100, '_session_config': None, '_save_checkpoints_steps': 2000, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_model_dir': 'trained_models/auto-encoder-01'}

Estimator Type: <class 'tensorflow.python.estimator.estimator.Estimator'>

WARNING:tensorflow:RunConfig.uid (from tensorflow.contrib.learn.python.learn.estimators.run_config) is experimental and may change or be removed at any time, and without warning.
WARNING:tensorflow:From /Users/khalidsalama/anaconda/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/monitors.py:267: BaseMonitor.__init__ (from tensorflow.contrib.learn.python.learn.monitors) is deprecated and will be removed after 2016-12-05.
Instructions for updating:
Monitors are deprecated. Please use tf.train.SessionRunHook.

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1000
Mode: train
Shuffle: True
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Saving checkpoints for 1 into trained_models/auto-encoder-01/model.ckpt.

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:20:52
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-1
INFO:tensorflow:Finished evaluation at 2017-11-22-19:20:54
INFO:tensorflow:Saving dict for global step 1: global_step = 1, loss = 36.6666, rmse = 6.05508
INFO:tensorflow:Validation (step 1): loss = 36.6666, rmse = 6.05508, global_step = 1
INFO:tensorflow:loss = 36.8122, step = 1
INFO:tensorflow:global_step/sec: 18.8371
INFO:tensorflow:loss = 19.9417, step = 101 (0.923 sec)
INFO:tensorflow:global_step/sec: 135.757
INFO:tensorflow:loss = 20.2463, step = 201 (0.737 sec)
INFO:tensorflow:global_step/sec: 135.379
INFO:tensorflow:loss = 21.9434, step = 301 (0.739 sec)
INFO:tensorflow:global_step/sec: 136.22
INFO:tensorflow:loss = 19.9245, step = 401 (0.735 sec)
INFO:tensorflow:global_step/sec: 135.154
INFO:tensorflow:loss = 20.3047, step = 501 (0.740 sec)
INFO:tensorflow:global_step/sec: 136.2
INFO:tensorflow:loss = 19.7709, step = 601 (0.735 sec)
INFO:tensorflow:global_step/sec: 135.783
INFO:tensorflow:loss = 20.0628, step = 701 (0.736 sec)
INFO:tensorflow:global_step/sec: 135.781
INFO:tensorflow:loss = 19.6728, step = 801 (0.737 sec)
INFO:tensorflow:global_step/sec: 135.648
INFO:tensorflow:loss = 20.0122, step = 901 (0.737 sec)
INFO:tensorflow:global_step/sec: 136.334
INFO:tensorflow:loss = 18.3527, step = 1001 (0.734 sec)
INFO:tensorflow:global_step/sec: 135.722
INFO:tensorflow:loss = 19.558, step = 1101 (0.737 sec)
INFO:tensorflow:global_step/sec: 133.491
INFO:tensorflow:loss = 20.7115, step = 1201 (0.748 sec)
INFO:tensorflow:global_step/sec: 136.761
INFO:tensorflow:loss = 18.9889, step = 1301 (0.732 sec)
INFO:tensorflow:global_step/sec: 135.387
INFO:tensorflow:loss = 19.1362, step = 1401 (0.740 sec)
INFO:tensorflow:global_step/sec: 130.222
INFO:tensorflow:loss = 19.5243, step = 1501 (0.767 sec)
INFO:tensorflow:global_step/sec: 125.292
INFO:tensorflow:loss = 20.2099, step = 1601 (0.798 sec)
INFO:tensorflow:global_step/sec: 125.07
INFO:tensorflow:loss = 19.5948, step = 1701 (0.800 sec)
INFO:tensorflow:global_step/sec: 113.148
INFO:tensorflow:loss = 20.4859, step = 1801 (0.885 sec)
INFO:tensorflow:global_step/sec: 104.108
INFO:tensorflow:loss = 20.3069, step = 1901 (0.959 sec)
INFO:tensorflow:Saving checkpoints for 2001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 44.5142

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:21:14
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-2001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:21:15
INFO:tensorflow:Saving dict for global step 2001: global_step = 2001, loss = 19.4033, rmse = 4.40357
INFO:tensorflow:Validation (step 2001): loss = 19.4033, rmse = 4.40357, global_step = 2001
INFO:tensorflow:loss = 20.4926, step = 2001 (5.152 sec)
INFO:tensorflow:global_step/sec: 27.2144
INFO:tensorflow:loss = 19.507, step = 2101 (0.769 sec)
INFO:tensorflow:global_step/sec: 130.143
INFO:tensorflow:loss = 19.3447, step = 2201 (0.769 sec)
INFO:tensorflow:global_step/sec: 120.044
INFO:tensorflow:loss = 18.582, step = 2301 (0.836 sec)
INFO:tensorflow:global_step/sec: 123.919
INFO:tensorflow:loss = 19.6243, step = 2401 (0.803 sec)
INFO:tensorflow:global_step/sec: 130.699
INFO:tensorflow:loss = 18.4446, step = 2501 (0.766 sec)
INFO:tensorflow:global_step/sec: 104.793
INFO:tensorflow:loss = 18.1941, step = 2601 (0.955 sec)
INFO:tensorflow:global_step/sec: 106.295
INFO:tensorflow:loss = 19.4379, step = 2701 (0.940 sec)
INFO:tensorflow:global_step/sec: 105.199
INFO:tensorflow:loss = 19.4128, step = 2801 (0.950 sec)
INFO:tensorflow:global_step/sec: 94.739
INFO:tensorflow:loss = 19.6151, step = 2901 (1.056 sec)
INFO:tensorflow:global_step/sec: 90.6647
INFO:tensorflow:loss = 19.2109, step = 3001 (1.103 sec)
INFO:tensorflow:global_step/sec: 99.181
INFO:tensorflow:loss = 19.79, step = 3101 (1.008 sec)
INFO:tensorflow:global_step/sec: 97.7458
INFO:tensorflow:loss = 20.1109, step = 3201 (1.023 sec)
INFO:tensorflow:global_step/sec: 102.42
INFO:tensorflow:loss = 18.6682, step = 3301 (0.976 sec)
INFO:tensorflow:global_step/sec: 102.155
INFO:tensorflow:loss = 19.2349, step = 3401 (0.979 sec)
INFO:tensorflow:global_step/sec: 109.222
INFO:tensorflow:loss = 19.082, step = 3501 (0.915 sec)
INFO:tensorflow:global_step/sec: 118.983
INFO:tensorflow:loss = 19.3111, step = 3601 (0.840 sec)
INFO:tensorflow:global_step/sec: 120.372
INFO:tensorflow:loss = 19.3439, step = 3701 (0.830 sec)
INFO:tensorflow:global_step/sec: 124.232
INFO:tensorflow:loss = 19.4874, step = 3801 (0.805 sec)
INFO:tensorflow:global_step/sec: 128.225
INFO:tensorflow:loss = 17.4151, step = 3901 (0.779 sec)
INFO:tensorflow:Saving checkpoints for 4001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 52.057

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:21:36
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-4001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:21:37
INFO:tensorflow:Saving dict for global step 4001: global_step = 4001, loss = 18.9114, rmse = 4.34696
INFO:tensorflow:Validation (step 4001): loss = 18.9114, rmse = 4.34696, global_step = 4001
INFO:tensorflow:loss = 19.3761, step = 4001 (5.228 sec)
INFO:tensorflow:global_step/sec: 24.5916
INFO:tensorflow:loss = 18.82, step = 4101 (0.760 sec)
INFO:tensorflow:global_step/sec: 134.809
INFO:tensorflow:loss = 19.2454, step = 4201 (0.742 sec)
INFO:tensorflow:global_step/sec: 134.01
INFO:tensorflow:loss = 18.9059, step = 4301 (0.746 sec)
INFO:tensorflow:global_step/sec: 131.966
INFO:tensorflow:loss = 18.4549, step = 4401 (0.758 sec)
INFO:tensorflow:global_step/sec: 131.312
INFO:tensorflow:loss = 19.3563, step = 4501 (0.761 sec)
INFO:tensorflow:global_step/sec: 133.818
INFO:tensorflow:loss = 20.4609, step = 4601 (0.748 sec)
INFO:tensorflow:global_step/sec: 136.914
INFO:tensorflow:loss = 18.7836, step = 4701 (0.730 sec)
INFO:tensorflow:global_step/sec: 133.155
INFO:tensorflow:loss = 18.1432, step = 4801 (0.750 sec)
INFO:tensorflow:global_step/sec: 134.631
INFO:tensorflow:loss = 18.5973, step = 4901 (0.745 sec)
INFO:tensorflow:global_step/sec: 132.684
INFO:tensorflow:loss = 18.8942, step = 5001 (0.752 sec)
INFO:tensorflow:global_step/sec: 135.948
INFO:tensorflow:loss = 19.7179, step = 5101 (0.735 sec)
INFO:tensorflow:global_step/sec: 136.043
INFO:tensorflow:loss = 18.4183, step = 5201 (0.735 sec)
INFO:tensorflow:global_step/sec: 133.034
INFO:tensorflow:loss = 18.9556, step = 5301 (0.751 sec)
INFO:tensorflow:global_step/sec: 134.138
INFO:tensorflow:loss = 18.2598, step = 5401 (0.746 sec)
INFO:tensorflow:global_step/sec: 134.692
INFO:tensorflow:loss = 20.168, step = 5501 (0.742 sec)
INFO:tensorflow:global_step/sec: 134.928
INFO:tensorflow:loss = 18.9459, step = 5601 (0.741 sec)
INFO:tensorflow:global_step/sec: 133.344
INFO:tensorflow:loss = 19.2701, step = 5701 (0.750 sec)
INFO:tensorflow:global_step/sec: 135.663
INFO:tensorflow:loss = 18.7345, step = 5801 (0.737 sec)
INFO:tensorflow:global_step/sec: 133.66
INFO:tensorflow:loss = 18.3431, step = 5901 (0.748 sec)
INFO:tensorflow:Saving checkpoints for 6001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 52.8989

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:21:55
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-6001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:21:56
INFO:tensorflow:Saving dict for global step 6001: global_step = 6001, loss = 18.7127, rmse = 4.32393
INFO:tensorflow:Validation (step 6001): loss = 18.7127, rmse = 4.32393, global_step = 6001
INFO:tensorflow:loss = 18.2383, step = 6001 (4.835 sec)
INFO:tensorflow:global_step/sec: 26.9766
INFO:tensorflow:loss = 18.5572, step = 6101 (0.762 sec)
INFO:tensorflow:global_step/sec: 131.218
INFO:tensorflow:loss = 17.8522, step = 6201 (0.764 sec)
INFO:tensorflow:global_step/sec: 131.552
INFO:tensorflow:loss = 19.0196, step = 6301 (0.759 sec)
INFO:tensorflow:global_step/sec: 132.704
INFO:tensorflow:loss = 19.2029, step = 6401 (0.753 sec)
INFO:tensorflow:global_step/sec: 129.618
INFO:tensorflow:loss = 17.8282, step = 6501 (0.772 sec)
INFO:tensorflow:global_step/sec: 132
INFO:tensorflow:loss = 18.9572, step = 6601 (0.758 sec)
INFO:tensorflow:global_step/sec: 129.792
INFO:tensorflow:loss = 18.4263, step = 6701 (0.771 sec)
INFO:tensorflow:global_step/sec: 128.714
INFO:tensorflow:loss = 19.0471, step = 6801 (0.776 sec)
INFO:tensorflow:global_step/sec: 132.019
INFO:tensorflow:loss = 19.7793, step = 6901 (0.758 sec)
INFO:tensorflow:global_step/sec: 130.515
INFO:tensorflow:loss = 18.1867, step = 7001 (0.766 sec)
INFO:tensorflow:global_step/sec: 130.165
INFO:tensorflow:loss = 19.4615, step = 7101 (0.769 sec)
INFO:tensorflow:global_step/sec: 131.122
INFO:tensorflow:loss = 18.5676, step = 7201 (0.763 sec)
INFO:tensorflow:global_step/sec: 130.906
INFO:tensorflow:loss = 18.5349, step = 7301 (0.764 sec)
INFO:tensorflow:global_step/sec: 129.595
INFO:tensorflow:loss = 18.5575, step = 7401 (0.772 sec)
INFO:tensorflow:global_step/sec: 129.746
INFO:tensorflow:loss = 18.6627, step = 7501 (0.771 sec)
INFO:tensorflow:global_step/sec: 131.377
INFO:tensorflow:loss = 19.1314, step = 7601 (0.761 sec)
INFO:tensorflow:global_step/sec: 130.888
INFO:tensorflow:loss = 20.5784, step = 7701 (0.764 sec)
INFO:tensorflow:global_step/sec: 129.733
INFO:tensorflow:loss = 18.3915, step = 7801 (0.772 sec)
INFO:tensorflow:global_step/sec: 131.907
INFO:tensorflow:loss = 19.3634, step = 7901 (0.758 sec)
INFO:tensorflow:Saving checkpoints for 8001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 54.4129

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:22:14
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-8001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:22:16
INFO:tensorflow:Saving dict for global step 8001: global_step = 8001, loss = 18.5652, rmse = 4.30669
INFO:tensorflow:Validation (step 8001): loss = 18.5652, rmse = 4.30669, global_step = 8001
INFO:tensorflow:loss = 18.8567, step = 8001 (4.705 sec)
INFO:tensorflow:global_step/sec: 27.4785
INFO:tensorflow:loss = 18.2087, step = 8101 (0.771 sec)
INFO:tensorflow:global_step/sec: 128.472
INFO:tensorflow:loss = 17.2026, step = 8201 (0.778 sec)
INFO:tensorflow:global_step/sec: 129.506
INFO:tensorflow:loss = 17.7978, step = 8301 (0.772 sec)
INFO:tensorflow:global_step/sec: 131.117
INFO:tensorflow:loss = 18.3097, step = 8401 (0.763 sec)
INFO:tensorflow:global_step/sec: 131.49
INFO:tensorflow:loss = 19.0983, step = 8501 (0.760 sec)
INFO:tensorflow:global_step/sec: 129.824
INFO:tensorflow:loss = 18.2968, step = 8601 (0.771 sec)
INFO:tensorflow:global_step/sec: 130.91
INFO:tensorflow:loss = 18.3628, step = 8701 (0.764 sec)
INFO:tensorflow:global_step/sec: 129.715
INFO:tensorflow:loss = 18.9475, step = 8801 (0.771 sec)
INFO:tensorflow:global_step/sec: 129.344
INFO:tensorflow:loss = 19.0161, step = 8901 (0.773 sec)
INFO:tensorflow:global_step/sec: 130.455
INFO:tensorflow:loss = 19.2569, step = 9001 (0.766 sec)
INFO:tensorflow:global_step/sec: 131.354
INFO:tensorflow:loss = 19.0711, step = 9101 (0.762 sec)
INFO:tensorflow:global_step/sec: 130.338
INFO:tensorflow:loss = 18.7674, step = 9201 (0.767 sec)
INFO:tensorflow:global_step/sec: 132.617
INFO:tensorflow:loss = 20.0051, step = 9301 (0.754 sec)
INFO:tensorflow:global_step/sec: 129.705
INFO:tensorflow:loss = 18.7149, step = 9401 (0.771 sec)
INFO:tensorflow:global_step/sec: 131.169
INFO:tensorflow:loss = 18.5734, step = 9501 (0.763 sec)
INFO:tensorflow:global_step/sec: 128.08
INFO:tensorflow:loss = 19.3119, step = 9601 (0.781 sec)
INFO:tensorflow:global_step/sec: 128.301
INFO:tensorflow:loss = 17.2134, step = 9701 (0.778 sec)
INFO:tensorflow:global_step/sec: 131.144
INFO:tensorflow:loss = 20.2189, step = 9801 (0.763 sec)
INFO:tensorflow:global_step/sec: 131.271
INFO:tensorflow:loss = 18.2155, step = 9901 (0.761 sec)
INFO:tensorflow:Saving checkpoints for 10001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 47.09

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:22:34
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-10001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:22:35
INFO:tensorflow:Saving dict for global step 10001: global_step = 10001, loss = 18.487, rmse = 4.29757
INFO:tensorflow:Validation (step 10001): loss = 18.487, rmse = 4.29757, global_step = 10001
INFO:tensorflow:loss = 18.6208, step = 10001 (4.865 sec)
INFO:tensorflow:global_step/sec: 28.2221
INFO:tensorflow:loss = 20.1192, step = 10101 (0.802 sec)
INFO:tensorflow:global_step/sec: 127.988
INFO:tensorflow:loss = 19.9426, step = 10201 (0.782 sec)
INFO:tensorflow:global_step/sec: 118.359
INFO:tensorflow:loss = 18.4945, step = 10301 (0.845 sec)
INFO:tensorflow:global_step/sec: 118.183
INFO:tensorflow:loss = 19.9309, step = 10401 (0.846 sec)
INFO:tensorflow:global_step/sec: 131.41
INFO:tensorflow:loss = 18.7485, step = 10501 (0.761 sec)
INFO:tensorflow:global_step/sec: 97.6836
INFO:tensorflow:loss = 18.4475, step = 10601 (1.023 sec)
INFO:tensorflow:global_step/sec: 130.894
INFO:tensorflow:loss = 18.5908, step = 10701 (0.764 sec)
INFO:tensorflow:global_step/sec: 129.668
INFO:tensorflow:loss = 18.2879, step = 10801 (0.771 sec)
INFO:tensorflow:global_step/sec: 130.525
INFO:tensorflow:loss = 18.8514, step = 10901 (0.766 sec)
INFO:tensorflow:global_step/sec: 130.405
INFO:tensorflow:loss = 18.598, step = 11001 (0.767 sec)
INFO:tensorflow:global_step/sec: 131.695
INFO:tensorflow:loss = 18.252, step = 11101 (0.759 sec)
INFO:tensorflow:global_step/sec: 128.565
INFO:tensorflow:loss = 19.4015, step = 11201 (0.779 sec)
INFO:tensorflow:global_step/sec: 110.455
INFO:tensorflow:loss = 18.9923, step = 11301 (0.904 sec)
INFO:tensorflow:global_step/sec: 132.227
INFO:tensorflow:loss = 18.753, step = 11401 (0.756 sec)
INFO:tensorflow:global_step/sec: 133.664
INFO:tensorflow:loss = 19.5469, step = 11501 (0.748 sec)
INFO:tensorflow:global_step/sec: 133.3
INFO:tensorflow:loss = 19.2192, step = 11601 (0.750 sec)
INFO:tensorflow:global_step/sec: 111.109
INFO:tensorflow:loss = 19.3636, step = 11701 (0.900 sec)
INFO:tensorflow:global_step/sec: 115.101
INFO:tensorflow:loss = 17.8409, step = 11801 (0.870 sec)
INFO:tensorflow:global_step/sec: 130.435
INFO:tensorflow:loss = 18.5233, step = 11901 (0.767 sec)
INFO:tensorflow:Saving checkpoints for 12001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 49.0935

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:22:54
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-12001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:22:55
INFO:tensorflow:Saving dict for global step 12001: global_step = 12001, loss = 18.4015, rmse = 4.28753
INFO:tensorflow:Validation (step 12001): loss = 18.4015, rmse = 4.28753, global_step = 12001
INFO:tensorflow:loss = 18.8426, step = 12001 (4.897 sec)
INFO:tensorflow:global_step/sec: 27.297
INFO:tensorflow:loss = 19.4703, step = 12101 (0.803 sec)
INFO:tensorflow:global_step/sec: 125.039
INFO:tensorflow:loss = 18.1342, step = 12201 (0.799 sec)
INFO:tensorflow:global_step/sec: 126.189
INFO:tensorflow:loss = 18.3588, step = 12301 (0.793 sec)
INFO:tensorflow:global_step/sec: 127.642
INFO:tensorflow:loss = 18.6479, step = 12401 (0.783 sec)
INFO:tensorflow:global_step/sec: 121.231
INFO:tensorflow:loss = 17.634, step = 12501 (0.824 sec)
INFO:tensorflow:global_step/sec: 121.613
INFO:tensorflow:loss = 19.4369, step = 12601 (0.823 sec)
INFO:tensorflow:global_step/sec: 127.072
INFO:tensorflow:loss = 18.2414, step = 12701 (0.787 sec)
INFO:tensorflow:global_step/sec: 122.056
INFO:tensorflow:loss = 19.5897, step = 12801 (0.819 sec)
INFO:tensorflow:global_step/sec: 121.851
INFO:tensorflow:loss = 17.7672, step = 12901 (0.820 sec)
INFO:tensorflow:global_step/sec: 126.547
INFO:tensorflow:loss = 17.7401, step = 13001 (0.790 sec)
INFO:tensorflow:global_step/sec: 129.949
INFO:tensorflow:loss = 19.3651, step = 13101 (0.770 sec)
INFO:tensorflow:global_step/sec: 122.748
INFO:tensorflow:loss = 18.504, step = 13201 (0.814 sec)
INFO:tensorflow:global_step/sec: 112.669
INFO:tensorflow:loss = 17.3638, step = 13301 (0.890 sec)
INFO:tensorflow:global_step/sec: 121.219
INFO:tensorflow:loss = 18.4762, step = 13401 (0.823 sec)
INFO:tensorflow:global_step/sec: 123.621
INFO:tensorflow:loss = 18.9894, step = 13501 (0.809 sec)
INFO:tensorflow:global_step/sec: 118.449
INFO:tensorflow:loss = 19.7383, step = 13601 (0.845 sec)
INFO:tensorflow:global_step/sec: 117.055
INFO:tensorflow:loss = 18.1484, step = 13701 (0.854 sec)
INFO:tensorflow:global_step/sec: 114.822
INFO:tensorflow:loss = 18.9536, step = 13801 (0.870 sec)
INFO:tensorflow:global_step/sec: 111.917
INFO:tensorflow:loss = 18.7444, step = 13901 (0.893 sec)
INFO:tensorflow:Saving checkpoints for 14001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 48.6264

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:23:15
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-14001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:23:16
INFO:tensorflow:Saving dict for global step 14001: global_step = 14001, loss = 18.2698, rmse = 4.27207
INFO:tensorflow:Validation (step 14001): loss = 18.2698, rmse = 4.27207, global_step = 14001
INFO:tensorflow:loss = 17.0911, step = 14001 (5.162 sec)
INFO:tensorflow:global_step/sec: 25.5294
INFO:tensorflow:loss = 17.9695, step = 14101 (0.812 sec)
INFO:tensorflow:global_step/sec: 123.659
INFO:tensorflow:loss = 18.6074, step = 14201 (0.808 sec)
INFO:tensorflow:global_step/sec: 119.237
INFO:tensorflow:loss = 17.7846, step = 14301 (0.839 sec)
INFO:tensorflow:global_step/sec: 132
INFO:tensorflow:loss = 17.9055, step = 14401 (0.757 sec)
INFO:tensorflow:global_step/sec: 129.322
INFO:tensorflow:loss = 17.3958, step = 14501 (0.773 sec)
INFO:tensorflow:global_step/sec: 132.278
INFO:tensorflow:loss = 17.9774, step = 14601 (0.756 sec)
INFO:tensorflow:global_step/sec: 128.374
INFO:tensorflow:loss = 17.0046, step = 14701 (0.780 sec)
INFO:tensorflow:global_step/sec: 131.09
INFO:tensorflow:loss = 17.5582, step = 14801 (0.763 sec)
INFO:tensorflow:global_step/sec: 129.039
INFO:tensorflow:loss = 18.5541, step = 14901 (0.775 sec)
INFO:tensorflow:global_step/sec: 124.296
INFO:tensorflow:loss = 18.5211, step = 15001 (0.804 sec)
INFO:tensorflow:global_step/sec: 126.259
INFO:tensorflow:loss = 19.1655, step = 15101 (0.792 sec)
INFO:tensorflow:global_step/sec: 124.912
INFO:tensorflow:loss = 18.749, step = 15201 (0.801 sec)
INFO:tensorflow:global_step/sec: 128.837
INFO:tensorflow:loss = 17.9731, step = 15301 (0.776 sec)
INFO:tensorflow:global_step/sec: 120.697
INFO:tensorflow:loss = 18.5142, step = 15401 (0.828 sec)
INFO:tensorflow:global_step/sec: 127.284
INFO:tensorflow:loss = 17.3209, step = 15501 (0.786 sec)
INFO:tensorflow:global_step/sec: 126.727
INFO:tensorflow:loss = 17.4243, step = 15601 (0.789 sec)
INFO:tensorflow:global_step/sec: 120.218
INFO:tensorflow:loss = 18.1924, step = 15701 (0.832 sec)
INFO:tensorflow:global_step/sec: 120.121
INFO:tensorflow:loss = 18.8689, step = 15801 (0.837 sec)
INFO:tensorflow:global_step/sec: 118.965
INFO:tensorflow:loss = 18.4031, step = 15901 (0.835 sec)
INFO:tensorflow:Saving checkpoints for 16001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 46.1817

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:23:35
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-16001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:23:37
INFO:tensorflow:Saving dict for global step 16001: global_step = 16001, loss = 18.1052, rmse = 4.2526
INFO:tensorflow:Validation (step 16001): loss = 18.1052, rmse = 4.2526, global_step = 16001
INFO:tensorflow:loss = 18.1852, step = 16001 (5.452 sec)
INFO:tensorflow:global_step/sec: 24.2936
INFO:tensorflow:loss = 17.962, step = 16101 (0.831 sec)
INFO:tensorflow:global_step/sec: 112.003
INFO:tensorflow:loss = 19.0617, step = 16201 (0.893 sec)
INFO:tensorflow:global_step/sec: 103.557
INFO:tensorflow:loss = 18.0857, step = 16301 (0.965 sec)
INFO:tensorflow:global_step/sec: 122.305
INFO:tensorflow:loss = 18.95, step = 16401 (0.817 sec)
INFO:tensorflow:global_step/sec: 129.274
INFO:tensorflow:loss = 17.3369, step = 16501 (0.774 sec)
INFO:tensorflow:global_step/sec: 127.343
INFO:tensorflow:loss = 17.7106, step = 16601 (0.785 sec)
INFO:tensorflow:global_step/sec: 127.252
INFO:tensorflow:loss = 17.9417, step = 16701 (0.787 sec)
INFO:tensorflow:global_step/sec: 127.553
INFO:tensorflow:loss = 18.7831, step = 16801 (0.784 sec)
INFO:tensorflow:global_step/sec: 125.496
INFO:tensorflow:loss = 17.5925, step = 16901 (0.797 sec)
INFO:tensorflow:global_step/sec: 123.585
INFO:tensorflow:loss = 18.3902, step = 17001 (0.810 sec)
INFO:tensorflow:global_step/sec: 116.123
INFO:tensorflow:loss = 18.6708, step = 17101 (0.860 sec)
INFO:tensorflow:global_step/sec: 127.957
INFO:tensorflow:loss = 17.7037, step = 17201 (0.782 sec)
INFO:tensorflow:global_step/sec: 129.946
INFO:tensorflow:loss = 18.1358, step = 17301 (0.769 sec)
INFO:tensorflow:global_step/sec: 132.583
INFO:tensorflow:loss = 17.5121, step = 17401 (0.754 sec)
INFO:tensorflow:global_step/sec: 132.032
INFO:tensorflow:loss = 18.6785, step = 17501 (0.757 sec)
INFO:tensorflow:global_step/sec: 128.467
INFO:tensorflow:loss = 18.3316, step = 17601 (0.778 sec)
INFO:tensorflow:global_step/sec: 129.369
INFO:tensorflow:loss = 17.4407, step = 17701 (0.774 sec)
INFO:tensorflow:global_step/sec: 128.354
INFO:tensorflow:loss = 17.6305, step = 17801 (0.779 sec)
INFO:tensorflow:global_step/sec: 126.157
INFO:tensorflow:loss = 18.8895, step = 17901 (0.792 sec)
INFO:tensorflow:Saving checkpoints for 18001 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:global_step/sec: 48.8043

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:23:56
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-18001
INFO:tensorflow:Finished evaluation at 2017-11-22-19:23:57
INFO:tensorflow:Saving dict for global step 18001: global_step = 18001, loss = 17.9375, rmse = 4.23275
INFO:tensorflow:Validation (step 18001): loss = 17.9375, rmse = 4.23275, global_step = 18001
INFO:tensorflow:loss = 18.6256, step = 18001 (4.824 sec)
INFO:tensorflow:global_step/sec: 27.9437
INFO:tensorflow:loss = 18.3272, step = 18101 (0.805 sec)
INFO:tensorflow:global_step/sec: 128.178
INFO:tensorflow:loss = 18.2022, step = 18201 (0.780 sec)
INFO:tensorflow:global_step/sec: 126.198
INFO:tensorflow:loss = 18.3417, step = 18301 (0.793 sec)
INFO:tensorflow:global_step/sec: 127.764
INFO:tensorflow:loss = 18.434, step = 18401 (0.783 sec)
INFO:tensorflow:global_step/sec: 128.719
INFO:tensorflow:loss = 18.7843, step = 18501 (0.777 sec)
INFO:tensorflow:global_step/sec: 128.456
INFO:tensorflow:loss = 17.3212, step = 18601 (0.778 sec)
INFO:tensorflow:global_step/sec: 125.946
INFO:tensorflow:loss = 17.7148, step = 18701 (0.794 sec)
INFO:tensorflow:global_step/sec: 110.881
INFO:tensorflow:loss = 17.4903, step = 18801 (0.902 sec)
INFO:tensorflow:global_step/sec: 120.793
INFO:tensorflow:loss = 18.2308, step = 18901 (0.828 sec)
INFO:tensorflow:global_step/sec: 125.856
INFO:tensorflow:loss = 19.2744, step = 19001 (0.795 sec)
INFO:tensorflow:global_step/sec: 126.958
INFO:tensorflow:loss = 17.1876, step = 19101 (0.788 sec)
INFO:tensorflow:global_step/sec: 124.351
INFO:tensorflow:loss = 18.3326, step = 19201 (0.804 sec)
INFO:tensorflow:global_step/sec: 125.822
INFO:tensorflow:loss = 17.4038, step = 19301 (0.794 sec)
INFO:tensorflow:global_step/sec: 126.627
INFO:tensorflow:loss = 18.8689, step = 19401 (0.790 sec)
INFO:tensorflow:global_step/sec: 120.958
INFO:tensorflow:loss = 18.4389, step = 19501 (0.826 sec)
INFO:tensorflow:global_step/sec: 127.711
INFO:tensorflow:loss = 18.4385, step = 19601 (0.783 sec)
INFO:tensorflow:global_step/sec: 125.923
INFO:tensorflow:loss = 17.6713, step = 19701 (0.795 sec)
INFO:tensorflow:global_step/sec: 129.752
INFO:tensorflow:loss = 19.4556, step = 19801 (0.772 sec)
INFO:tensorflow:global_step/sec: 123.638
INFO:tensorflow:loss = 16.5231, step = 19901 (0.809 sec)
INFO:tensorflow:Saving checkpoints for 20000 into trained_models/auto-encoder-01/model.ckpt.
INFO:tensorflow:Loss for final step: 17.87.

* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 100
Epoch Count: 1
Mode: eval
Shuffle: False
================

[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Starting evaluation at 2017-11-22-19:24:16
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-20000
INFO:tensorflow:Finished evaluation at 2017-11-22-19:24:17
INFO:tensorflow:Saving dict for global step 20000: global_step = 20000, loss = 17.9489, rmse = 4.23404
.......................................
Experiment finished at 19:24:17

Experiment elapsed time: 214.089324 seconds

6. Use the trained model to encode data (prediction)


In [12]:
import itertools

DATA_SIZE = 2000

input_fn = lambda: csv_input_fn(
    TRAIN_DATA_FILES_PATTERN,
    mode=tf.contrib.learn.ModeKeys.INFER,
    num_epochs=1,
    batch_size=500
)

estimator = create_estimator(run_config, hparams)

predictions = estimator.predict(input_fn=input_fn)
predictions = itertools.islice(predictions, DATA_SIZE)
predictions = list(map(lambda item: list(item["encoding"]), predictions))

print(predictions[:5])


INFO:tensorflow:Using config: {'_task_type': None, '_task_id': 0, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x121ab5a20>, '_master': '', '_num_ps_replicas': 0, '_num_worker_replicas': 0, '_environment': 'local', '_is_chief': True, '_evaluation_master': '', '_tf_config': gpu_options {
  per_process_gpu_memory_fraction: 1
}
, '_tf_random_seed': 19830610, '_save_summary_steps': 100, '_save_checkpoints_secs': None, '_log_step_count_steps': 100, '_session_config': None, '_save_checkpoints_steps': 2000, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_model_dir': 'trained_models/auto-encoder-01'}

Estimator Type: <class 'tensorflow.python.estimator.estimator.Estimator'>


* data input_fn:
================
Input file(s): data/data-*.csv
Batch size: 500
Epoch Count: 1
Mode: infer
Shuffle: False
================

WARNING:tensorflow:Input graph does not contain a QueueRunner. That means predict yields forever. This is probably a mistake.
[64]->[30, 3]-[30]->[64]
INFO:tensorflow:Restoring parameters from trained_models/auto-encoder-01/model.ckpt-20000
[[10.613751, 21.388153, 9.109767], [0.0, 6.1416941, 45.451698], [10.163795, 6.5200195, 21.493673], [28.593414, 30.766495, 10.59348], [16.369936, 23.12347, 10.659847]]

Visualise Encoded Data


In [13]:
y = pd.read_csv("data/data-01.csv", header=None, index_col=0)[65]

data_reduced = pd.DataFrame(predictions, columns=['c1','c2','c3'])
data_reduced['class'] = y
data_reduced.head()


Out[13]:
c1 c2 c3 class
0 10.613751 21.388153 9.109767 2
1 0.000000 6.141694 45.451698 0
2 10.163795 6.520020 21.493673 0
3 28.593414 30.766495 10.593480 2
4 16.369936 23.123470 10.659847 2

In [14]:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xs=data_reduced.c1, ys=data_reduced.c2, zs=data_reduced.c3, c=data_reduced['class'], marker='o')
plt.show()


Notes:

  1. You can effectively implement a (linear) PCA by having only one hidden layer with no activation function

  2. To improve the efficiency of training the model, the weights of the encoder and decoder layers can be tied (i.e., have the same values)


In [ ]: